unit RakeOffPayBill;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DetailBill, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, cxContainer, cxEdit, dxSkinsCore,
  dxSkinsDefaultPainters, dxSkinscxPCPainter, cxStyles, cxCustomData,
  cxFilter, cxData, cxDataStorage, DB, cxDBData, Menus, MemDS, DBAccess,
  Uni, Provider, DBClient, cxPropertiesStore, DBActns, StdActns, ActnList,
  ImgList, dxSkinsForm, cxProgressBar, cxDBLookupComboBox, StdCtrls,
  cxButtons, ExtCtrls, dxGDIPlusClasses, cxImage, cxSpinEdit, cxTimeEdit,
  cxDBEdit, cxGridLevel, cxClasses, cxGridCustomView, MisString,
  cxGridCustomTableView, cxGridTableView, cxGridBandedTableView,
  cxGridDBBandedTableView, cxGrid, cxPC, cxCalendar, cxDropDownEdit,
  cxCalc, cxLabel, cxTextEdit, cxMaskEdit, cxLookupEdit, cxDBLookupEdit,
  dxBarBuiltInMenu, cxNavigator, System.Actions, System.ImageList;

type
  TfrmRakeOffPayBill = class(TfrmDetailBill)
    procedure dspDetailBeforeUpdateRecord(Sender: TObject;
      SourceDS: TDataSet; DeltaDS: TCustomClientDataSet;
      UpdateKind: TUpdateKind; var Applied: Boolean);
    procedure dspMasterBeforeUpdateRecord(Sender: TObject;
      SourceDS: TDataSet; DeltaDS: TCustomClientDataSet;
      UpdateKind: TUpdateKind; var Applied: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmRakeOffPayBill: TfrmRakeOffPayBill;

implementation

{$R *.dfm}

procedure TfrmRakeOffPayBill.dspDetailBeforeUpdateRecord(Sender: TObject;
  SourceDS: TDataSet; DeltaDS: TCustomClientDataSet;
  UpdateKind: TUpdateKind; var Applied: Boolean);
begin
  inherited;
  if (UpdateKind = ukModify) and (DeltaDS.FieldByName(KeyField).OldValue > TMP_ID) then
  begin
    qryUpdate.SQL.Clear;
    qryUpdate.SQL.Text := 'Update TB_RakeOffPayDTL set bid=:bid,bno=:bno,borderno=:borderno,deptid=:deptid,empid=:empid,filid=:filid,   '
      + 'relationcount=:relationcount,relationbtype=:relationbtype,relationbid=:relationbid,relationbno=:relationbno,          '
      + 'custom1=:custom1,custom2=:custom2,custom3=:custom3,custom4=:custom4,custom5=:custom5,             '
      + 'custom6=:custom6,custom7=:custom7,custom8=:custom8,custom9=:custom9,custom10=:custom10,explan=:explan,     '
      + 'custom11=:custom11,custom12=:custom12,custom13=:custom13,custom14=:custom14,custom15=:custom15  '
//      + 'custom16=:custom16,custom17=:custom17,custom18=:custom18,custom19=:custom19,custom20=:custom20,  '
    + ' where bid=:OLD_bid and bno=:OLD_bno ';
    SetUpdateValue(qryUpdate, DeltaDS, Applied);
  end
  else if (UpdateKind = ukInsert) or (DeltaDS.FieldByName(KeyField).OldValue = TMP_ID) then
  begin
    qryUpdate.SQL.Clear;
    qryUpdate.SQL.Text := 'Insert into TB_RakeOffPayDTL(bid,bno,borderno,deptid,empid,filid,'
      + 'relationcount,relationbtype,relationbid,relationbno,'
      + 'custom1,custom2,custom3,custom4,custom5,custom6,custom7,custom8,custom9,custom10,'
      + 'custom11,custom12,custom13,custom14,custom15,'
//      + 'custom16,custom17,custom18,custom19,custom20,'
      + 'explan,create_time) Values (:bid,:bno,:borderno,:deptid,:empid,:filid,      '
      + ':relationcount,:relationbtype,:relationbid,:relationbno,    '
      + ':custom1,:custom2,:custom3,:custom4,:custom5,:custom6,:custom7,:custom8,:custom9,:custom10,     '
      + ':custom11,:custom12,:custom13,:custom14,:custom15,'
//      + ':custom16,:custom17,:custom18,:custom19,:custom20,'
      + ':explan,:create_time)';
    SetUpdateValue(qryUpdate, DeltaDS, Applied);
  end;
end;

procedure TfrmRakeOffPayBill.dspMasterBeforeUpdateRecord(Sender: TObject;
  SourceDS: TDataSet; DeltaDS: TCustomClientDataSet;
  UpdateKind: TUpdateKind; var Applied: Boolean);
begin
  inherited;
//balanceid=:balanceid,accountid=:accountid,voucherid=:voucherid,costvoucherid=:costvoucherid,relationamt=:relationamt,
  if (UpdateKind = ukModify) and (not FbNewRecord) then
  begin
    qryUpdate.SQL.Clear;
    qryUpdate.SQL.Text := 'Update TB_RakeOffPay set bid=:bid,bkind=:bkind,bstate=:bstate,bcode=:bcode,bdate=:bdate,     '
      + 'filid=:filid,deptid=:deptid,create_by=:create_by,'
      + 'check_by=:check_by,empid=:empid,relationcount=:relationcount,amount=:amount,            '
      + 'custom1=:custom1,custom2=:custom2,custom3=:custom3,custom4=:custom4,custom5=:custom5,  '
      + 'custom6=:custom6,custom7=:custom7,custom8=:custom8,custom9=:custom9,custom10=:custom10,update_time=:update_time,         '
      + 'custom11=:custom11,custom12=:custom12,custom13=:custom13,custom14=:custom14,custom15=:custom15,  '
      + 'remark=:remark where bid=:OLD_bid ';
    SetUpdateValue(qryUpdate, DeltaDS, Applied);
  end
  else if (UpdateKind = ukInsert) or (FbNewRecord) then
  begin
    qryUpdate.SQL.Clear;
    qryUpdate.SQL.Text := 'Insert into TB_RakeOffPay(bid,bkind,bstate,bcode,bdate,filid,deptid,create_by,'
      + 'check_by,empid,relationcount,amount,  '
      + 'custom1,custom2,custom3,custom4,custom5,custom6,custom7,custom8, '
      + 'custom9,custom10,update_time,remark,create_time,'
      + 'custom11,custom12,custom13,custom14,custom15,check_time'
      + ') Values (:bid,   '
      + ':bkind,:bstate,:bcode,:bdate,:filid,:deptid,:create_by,:check_by, '
      + ':empid,:relationcount,:amount,  '
      + ':custom1,:custom2,:custom3,:custom4,:custom5,:custom6,     '
      + ':custom7,:custom8,:custom9,:custom10,:update_time,:remark,:create_time, '
      + ':custom11,:custom12,:custom13,:custom14,:custom15,:check_time)';
    SetUpdateValue(qryUpdate, DeltaDS, Applied);
  end;
end;

end.

